(function() {
  var db, handler, mongoose, onConnect, onDisconnect, host, port, dbname;
 
  mongoose = require('mongoose');
 
  host    = 'localhost';
  port    = '27017';
  dbname  = 'chat';
  
  handler = null;
 
  onConnect = function() {
    return console.log('Connected to Mongodb via Mongoose');
  };
 
  onDisconnect = function() {
    return console.log('Disconnected from Mongodb');
  };
 
  module.exports = db = function() {
    return handler = mongoose.connect(host,dbname,port);
  };
 
  module.exports.close = function() {
    return handler.disconnect(onDisconnect);
  };
 
  module.exports.user = mongoose.model('user', require('./user'));
  module.exports.message = mongoose.model('message', require('./message'));
 
}).call(this);
